import {
  getOrderByUserIdAPI
} from '../../../../api/order'
Page({
  data: {
    userId: 0,
    orderList: [],
    orderDetail: null,
    id: 0
  },
  async getOrderByUserId(userId) {
    let that = this
    await getOrderByUserIdAPI(userId).then(res => {
      if (res.code == 200) {
        that.setData({
          orderList: res.result
        })
        let arr = res.result.filter((item) => {
          console.log(item.id);
          return item.id == that.data.id
        })
        that.setData({
          orderDetail: arr[0]
        })

      }
    })
  },
  onLoad(options) {
    let user = wx.getStorageSync('user')
    if (user) {
      this.setData({
        userId: user.id,
      })
    }
    this.setData({
      id: JSON.parse(options.id)
    })
    this.getOrderByUserId(this.data.userId)
  },
  onShow() {
    this.onLoad()
  },
})